<template>
    <div id="pulpTest">
        <!-- 查询 -->
        <el-popover placement="bottom-start" width="830" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
            <el-form :inline="true" :model="searchList" label-width="75px" class="demo-ruleForm">
                <el-form-item label="浆员卡号" style="margin-bottom: 0;"><el-input v-model="searchList.cardid" style="width: 100px;"></el-input></el-form-item>
                <el-form-item label="浆员姓名" style="margin-bottom: 0;"><el-input v-model="searchList.name" style="width: 100px;"></el-input></el-form-item>
                <el-form-item label="创建时间" style="margin-bottom: 0;"><el-date-picker v-model="searchList.time" type="daterange" style="width: 300px;" range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" align="right"></el-date-picker></el-form-item>
                <el-button type="primary" @click="searchData">提交</el-button>
            </el-form>
            <el-button slot="reference" type="primary">查询</el-button>
        </el-popover>

        <!-- 表格 -->
        <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border class="company-table" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable align="center" min-width="40"></el-table-column>
            <el-table-column prop="cardId" label="卡号" sortable min-width="90"></el-table-column>
            <el-table-column prop="contributionPerson" label="姓名" sortable min-width="100"></el-table-column>
            <el-table-column prop="bodyCheckWorkerName" label="体检医生" sortable min-width="110"></el-table-column>
            <el-table-column prop="createNurseName" label="体检护士" sortable min-width="110"></el-table-column>
            <el-table-column prop="registerOrder" label="登记序号" sortable min-width="110"></el-table-column>
            <el-table-column prop="bodyCheckOrder" label="体检序号" sortable min-width="110"></el-table-column>
            <el-table-column prop="authMethod" label="认证方式" :formatter="formatterAuthMethod" sortable min-width="110"></el-table-column>
            <el-table-column prop="bodyStartTime" label="体检开始时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="recodeCreateTime" label="记录创建时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="recodeStatus" label="记录状态" :formatter="formatterRecodeStatus"  sortable min-width="110"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" min-width="75">
                <template slot-scope="scope">
                    <el-button  @click="updateDialog(scope.row)" type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="tableData.length"></el-pagination>

        <!-- 详情 -->
        <el-dialog :title="dialogTitle" :visible.sync="isDialog" width="1100px" top="60px" :close-on-click-modal="false" >
            <div :style="dialogHeight">
                <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                <!-- 浆员基本信息 -->
                 <pulpwork-info v-bind:cardid="dialogList.providerNo"></pulpwork-info>
                <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>生命体征</span></h3>
                <el-form :inline="true" :model="dialogList" :rules="dialogRules" ref="dialogRules" label-width="120px" class="demo-ruleForm">
                    <el-form-item label="体重/kg" prop="weight"><el-input v-model="dialogList.weight"></el-input></el-form-item>
                    <el-form-item label="体温/℃" prop="animalHeat"><el-input v-model="dialogList.animalHeat"></el-input></el-form-item>
                    <el-form-item label="脉搏/B/M" prop="pulse"><el-input v-model="dialogList.pulse"></el-input></el-form-item>
                    <el-form-item label="血压/KPa">
                       <el-row style="width: 200px;">
                           <el-col :span="11"><el-form-item prop="lowBlood"><el-input  v-model="dialogList.lowBlood"></el-input></el-form-item></el-col>
                           <el-col class="line" :span="2">-</el-col>
                           <el-col :span="11"><el-form-item prop="highBlood"><el-input  v-model="dialogList.highBlood"></el-input></el-form-item></el-col>
                       </el-row>
                    </el-form-item>
                    <el-form-item label="体检护士"><el-input v-model="dialogList.createNurseName" disabled></el-input></el-form-item>
                </el-form>

                <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>征询项目</span></h3>
                <el-row :gutter="20" style="margin-right: 0;" >
                    <el-col :span="8">
                        <el-row :gutter="20" style="margin-right: 0;" >
                            <el-col :span="12">
                                <el-upload class="avatar-uploader"
                                           ref="appendix"
                                           style="height: 230px;"
                                           :action="appendixUrl"
                                           :show-file-list="false"
                                           :on-success="handleAvatarSuccess"
                                           :before-upload="beforeAvatarUpload">
                                    <img v-if="dialogList.singlePhoto" :src="dialogList.singlePhoto" class="avatar" />
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </el-col>
                            <el-col :span="12">
                                <el-upload class="avatar-uploader"
                                           style="height: 230px;"
                                           :action="appendixUrl"
                                           :show-file-list="false"
                                           :on-success="handleAvatarSuccess1"
                                           :before-upload="beforeAvatarUpload"
                                >
                                    <img v-if="dialogList.singlePhoto1" :src="dialogList.singlePhoto1" class="avatar" />
                                    <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                </el-upload>
                            </el-col>
                        </el-row>
                    </el-col>
                    <el-col :span="16">
                        <el-form :inline="true" :model="dialogList" label-width="100px" class="demo-ruleForm">
                            <el-form-item label="上传时间"><el-input v-model="dialogList.singleUploadTime" ></el-input></el-form-item>
                            <el-form-item label="胸部"><el-select v-model="dialogList.chest"><el-option value="" label="【空】"></el-option><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="腹部"><el-select v-model="dialogList.abdomen"><el-option value="" label="【空】"></el-option><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="皮肤"><el-select v-model="dialogList.skin"><el-option value="" label="【空】"></el-option><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="五官"><el-select v-model="dialogList.facial"><el-option value="" label="【空】"></el-option><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="四肢"><el-select v-model="dialogList.limbs"><el-option value="" label="【空】"></el-option><el-option :value="1" label="正常"></el-option><el-option :value="0" label="不正常"></el-option></el-select></el-form-item>
                            <el-form-item label="健康征询"><el-select v-model="dialogList.healthSingle"><el-option :value="1" label="是"></el-option><el-option :value="0" label="否"></el-option></el-select></el-form-item>
                            <el-form-item label="体检结果"><el-select v-model="dialogList.bodyCheckResult"><el-option value="" label="[空]"></el-option><el-option :value="0" label="不合格"></el-option><el-option :value="1" label="合格"></el-option><el-option :value="2" label="复检"></el-option></el-select></el-form-item>
                            <el-form-item v-if="dialogList.bodyCheckResult=='0'" label="拒绝类型"><el-select v-model="dialogList.refuseType"><el-option :value="0" label="暂拒"></el-option><el-option :value="1" label="永拒"></el-option></el-select></el-form-item>
                            <el-form-item v-if="dialogList.refuseType=='0'" label="暂拒原因"><el-input v-model="dialogList.outReason"></el-input></el-form-item>
                            <el-form-item v-if="dialogList.refuseType=='1'" label="永拒原因"><el-select v-model="dialogList.refuseReason"><el-option v-for="item in codeData2" :key="item.code" :value="item.code" :label="item.name"></el-option></el-select></el-form-item>
                            <el-form-item label="体检医生"><el-select v-model="dialogList.bodyCheckWorker"><el-option v-for="item in dictorData" :key="item.id" :value="item.id" :label="item.name"></el-option></el-select></el-form-item>
                        </el-form>
                    </el-col>
                </el-row>

                <h3 class="dialog-plate-title" style="margin-top: 15px;"><span>其他</span></h3>
                <el-form :inline="true" :model="dialogList" label-width="120px" class="demo-ruleForm">
                    <el-form-item label="献浆人"><el-input v-model="dialogList.contributionPerson" disabled></el-input></el-form-item>
                    <el-form-item label="登记序号"><el-input v-model="dialogList.registerOrder" disabled></el-input></el-form-item>
                    <el-form-item label="体检编号"><el-input v-model="dialogList.bodyCheckNo" disabled></el-input></el-form-item>
                    <el-form-item label="体检序号"><el-input v-model="dialogList.bodyCheckOrder" disabled></el-input></el-form-item>
                    <el-form-item label="体检开始时间"><el-input v-model="dialogList.bodyStartTime" disabled></el-input></el-form-item>
                    <el-form-item label="记录创建时间"><el-input v-model="dialogList.recodeCreateTime" disabled></el-input></el-form-item>
                    <el-form-item label="体检结束时间"><el-input v-model="dialogList.bodyEndTime" disabled></el-input></el-form-item>
                    <el-form-item label="记录结束时间"><el-input v-model="dialogList.recodeEndTime" disabled></el-input></el-form-item>
                    <el-form-item label="记录状态"><el-select v-model="dialogList.recodeStatus" disabled><el-option :value="0" label="待处理"></el-option><el-option :value="1" label="已处理"></el-option></el-select></el-form-item>
                </el-form>
            </div>
            <div slot="footer">
                <el-button type="primary" @click="submitDialog" >提交</el-button>
            </div>
        </el-dialog>


    </div>
</template>

<script>
import pulpworkInfo from 'operationManage/components/pulpworkInfo.vue'
    export default {
        name: "pulpTest",
        components:{
            pulpworkInfo
        },
        data(){
            const validateWeight = (rule, value, callback) => {
                if (value < 45  ||  value > 150) {
                    callback( new Error('体重不能高于150Kg，低于45Kg')   )
                } else {
                    callback()
                }
            };
            const validateAnimalHeat = (rule, value, callback) => {
                if (value < 36.3  ||  value > 37.2) {
                    callback( new Error('体重不能高于37.2 ℃，低于36.3 ℃') )
                } else {
                    callback()
                }
            };
            const validatePulse = (rule, value, callback) => {
                if (value < 60  ||  value > 100) {
                    callback( new Error('体重不能高于100/B/M，低于60/B/M') )
                } else {
                    callback()
                }
            };
            const validateLowBlood = (rule, value, callback) => {
                if (value < 8  ||  value > 12) {
                    callback( new Error('低压不能低于8/KPa，高于12/KPa') )
                } else {
                    callback()
                }
            };
            const validateHighBlood  = (rule, value, callback) => {
                if (value < 12  ||  value > 20) {
                    callback( new Error('高压不能低于12/KPa，高于20/KPa') )
                } else {
                    callback()
                }
            };
            return {
                tokenId: sessionStorage.getItem("tokenId"),
                currentPage: 1,
                pagesize: 10,
                activeName:'1',
                tableHeight: document.documentElement.clientHeight - 160,
                tableData:[],

                // 查询
                searchList:{
                    name:'',
                    cardid:'',
                    time:'',
                    bigCreateTime:'',
                    lessCreateTime:''
                },

                //基本信息
                dialogBasicList:{
                    address: "",
                    age: "",
                    id: "",
                    idNo: "",
                    name: "",
                    phone: "",
                    sex: "",
                },

                //详情
                isDialog:false,
                dialogTitle:'',
                dialogList:{
                    registerOrder: '',
                    bodyCheckOrder: '',
                    abdomen: '',
                    animalHeat: '',
                    assessor: '',
                    authMethod: '',
                    lowBlood:'',
                    highBlood:'',
                    bodyCheckNo: '',
                    bodyCheckPhoto: '',
                    bodyCheckResult: '',
                    bodyCheckWorker: '',
                    bodyCheckWorkerName:"",
                    bodyCode: '',
                    bodyEndTime: '',
                    bodyRecodeId: '',
                    bodyStartTime: '',
                    chest: '',
                    consultInputTime: '',
                    contributionPerson: '',
                    createNurse: '',
                    createNurseName: '',
                    facial: '',
                    healthSingle: '',
                    limbs: '',
                    outReason: '',
                    providerNo: '',
                    pulse: '',
                    recodeCreateTime: '',
                    recodeEndTime: '',
                    recodeStatus: '',
                    refuseReason: '',
                    refuseType: '',
                    registerNo: '',
                    signInputTime: '',
                    singlePhoto: '',
                    singlePhoto1: '',
                    singleUploadTime: '',
                    skin: '',
                    threshold: '',
                    weight: '',
                },
                appendixUrl:"/api/adscm/filesystem/abc",
                dialogHeight: {
                    height: document.documentElement.clientHeight - 230+ 'px',
                    overflowY: 'auto',
                },

                dialogRules: {
                    weight: [
                        { required: true, message: '请输入体重...', trigger: 'blur' },
                        {  type: 'number', message: '体重不能高于150Kg，低于45Kg', trigger: 'blur', validator:validateWeight},
                    ],
                    animalHeat: [
                        { required: true, message: '请输入体温...', trigger: 'blur' },
                        { type: 'number', message: '体重不能高于37.2 ℃，低于36.3 ℃', trigger: 'blur',validator:validateAnimalHeat }
                    ],
                    pulse: [
                        { required: true, message: '请输入脉搏...', trigger: 'blur' },
                        { type: 'number', message: '体重不能高于100/B/M，低于60/B/M', trigger: 'blur',validator:validatePulse},
                    ],
                    lowBlood: [
                        { required: true, message: '请输入低血压...', trigger: 'blur' },
                        { type: 'number', message: '低压不能高于8/KPa，低于12/KPa', trigger: 'blur',validator:validateLowBlood},
                    ],
                    highBlood: [
                        { required: true, message: '请输入高血压...', trigger: 'blur' },
                        { type: 'number', message: '高压不能高于12/KPa，低于20/KPa', trigger: 'blur',validator:validateHighBlood},
                    ],
                },

            }
        },
        created() {
            let time = this.timestampToTime(new Date()).substr(0,10);
            this.getData('/api/adscm/application/bodyCheck/queryByTime?tokenId='+this.tokenId+'&recodeTime=' + time);
            this.getNurseData();
            this.getDoctorData();
            this.getCodeData(2);
        },
        methods: {
            getData(url) {

                console.log( url )

                let _this = this;
                let loading = this.$loading({
                    target: document.querySelector(".wrapper > .content-box"),
                    lock: true,
                    text: '正在努力加载中...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(0, 0, 0, 0.8)'
                });
                this.$http({
                    url:url,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.tableData = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                    loading.close();
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                    loading.close();
                })
            },

            //搜索
            searchData(){
              let time1 = this.timestampToTime( this.searchList.time[0]).substr(0,10);
              let time2 = this.timestampToTime( this.searchList.time[1]).substr(0,10);
              if ( this.searchList.cardid==='' && this.searchList.name !== ''  ) {
                  this.getData('/api/adscm/application/bodyCheck/queryByName?tokenId='+this.tokenId+'&name=' + this.searchList.name + '&bigCreateTime=' + time1 + '&lessCreateTime=' +time2);
              } else if ( this.searchList.name === '' && this.searchList.cardid !== '' ) {
                  this.getData('/api/adscm/application/bodyCheck/queryByTime?tokenId='+this.tokenId+'&cardid=' + this.searchList.cardid + '&bigCreateTime=' + time1 + '&lessCreateTime=' +time2);
              } else if ( this.searchList.name === '' && this.searchList.cardid === '' ) {
                  this.getData('/api/adscm/application/bodyCheck/queryByTime?tokenId='+this.tokenId+'&name=' + this.searchList.name + '&cardid=' + this.searchList.cardid + '&bigCreateTime=' + time1 + '&lessCreateTime=' +time2);
              }
            },


            // 头像上传
            handleAvatarSuccess(res, file,fileList) {
                console.log( res,file )
                this.dialogList.singlePhoto = res;
            },
            handleAvatarSuccess1(res, file) {
                this.dialogList.singlePhoto1 = res;
            },
            beforeAvatarUpload(file) {
                const isJPG = file.type.substr(0,5) === 'image';
                const isLt1M = file.size / 1024 / 1024 < 1;

                if (!isJPG) {
                    this.$message.error('只能上传图片!');
                }
                if (!isLt1M) {
                    this.$message.error('上传头像图片大小不能超过 1MB!');
                }
                return isJPG && isLt1M;
            },

            //基本信息
            getBasicDialogData(id) {
                let _this = this;
                // this.$http({
                //     url: '/api/adscm/application/bodyCheck/bodyCheckInfo?cardid='+ id,
                //     method: 'post',
                //     headers: {'X-Requested-With': 'XMLHttpRequest'},
                // }).then(function (res) {
                //     console.log( res.data )
                //     if (res.data.statusCode == 200) {
                //         _this.dialogBasicList = res.data.content;
                //     } else {
                //         _this.$message.error(res.data.desc);
                //     }
                // }).catch(function (catchres) {
                //     _this.$message.error("加载失败！请重新加载...");
                // })
            },
            updateDialog(row){
                console.log( row )
                this.isDialog = true;
                this.dialogTitle = '详情信息';
                this.activeName='1';
                this.getBasicDialogData(row.providerNo);
                this.dialogList = row;
                this.dialogList.bodyCheckWorker = parseInt(row.bodyCheckWorker);

            },
            submitDialog(){
                let _this = this;
                delete this.dialogList['createNurseName'];
                delete this.dialogList['bodyCheckWorkerName'];
                console.log(  this.dialogList  )
                this.$http({
                    url: '/api/adscm/application/bodyCheck/update?tokenId='+ _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                    data:_this.dialogList
                }).then(function (res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                        let time = _this.timestampToTime(new Date()).substr(0,10);
                        _this.getData('/api/adscm/application/bodyCheck/queryByTime?tokenId='+_this.tokenId+'&recodeTime=' + time);
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },


            timestampToTime (timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + '-';
                    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + " ";
                    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ":";
                    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ":";
                    let s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
                    return timestamp ? Y + M + D + h + m + s : '';
                } else {
                    return '';
                }
            },
            handleSizeChange(size) {
                this.pagesize = size;
            },
            handleCurrentChange(currentPage) {
                this.currentPage = currentPage;
            },



        },
    }
</script>

<style scoped>

</style>
